<!--
 * @Author: hl
 * @Date: 2023-07-11 13:52:31
 * @LastEditors: lh
 * @LastEditTime: 2023-10-12 14:34:02
-->
<template>
  <div>
    <!-- :searchDataList="searchDataListJy" -->
    <tabCom
      @Refresh="Refresh"
      @search-callback="searchCallback"
      :title="'旁站管理'"
      :operation-api="operationApiA"
      :table-data-rule="tableDataRuleA"
      :search-data-list="searchDataListJy"
      :needPagination="true"
      :update_show_key="'id'"
      :update_show_value="[0]"
      :formDataWidth="'30%'"
    >
      <template #add="{ formData }">
        <template v-for="(item, index) in searchDataListJyEdit" :key="index">
          <el-form-item
            :label="item.title"
            v-if="
              (!formData['bystanderType'] && index == 0) ||
              (formData['bystanderType'] != '' && item.showArr && item.showArr.includes(formData['bystanderType']))
            "
          >
            <el-input v-if="!item.type" v-model="formData[item.name]" placeholder="请输入" />
            <el-input
              v-else-if="item.type == 'number'"
              type="number"
              v-model="formData[item.name]"
              placeholder="请输入"
            />
            <el-date-picker
              v-else-if="item.type == 'timeday'"
              v-model="formData[item.name]"
              type="date"
              format="YYYY/MM/DD"
              placeholder="请选择"
            />
            <el-date-picker
              v-else-if="item.type == 'datetime'"
              v-model="formData[item.name]"
              type="datetime"
              format="YYYY/MM/DD HH:mm:ss"
              placeholder="请选择"
            />
            <upfilebox
              v-else-if="item.type == 'file'"
              fileType="file"
              v-model="formData[item.name]"
              v-model:name="formData[item.prop]"
            ></upfilebox>
            <el-date-picker
              @change="chooseTimeChange(formData[item.name])"
              v-else-if="item.type == 'time'"
              v-model="formData[item.name]"
              type="datetimerange"
              format="YYYY/MM/DD"
              value-format="YYYYMMDD"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            />
            <el-select
              v-else-if="item.type == 'select' && item!.list!.length > 0"
              v-model="formData[item.name]"
              default-first-option
              :reserve-keyword="false"
              clearable
              allow-create
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="items in item.list"
                :key="items.value"
                :label="items.label || items.name"
                :value="items.value || items.id"
              />
            </el-select>
            <el-select
              v-else-if="item.type == 'selectLable'"
              v-model="formData[item.name]"
              default-first-option
              :reserve-keyword="false"
              clearable
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="items in item.list"
                :key="items.value"
                :label="items.label || items.name"
                :value="items.label || items.name"
              />
            </el-select>
            <el-select
              v-else-if="item.type == 'multipleSelect'"
              multiple
              v-model="formData[item.name]"
              default-first-option
              :reserve-keyword="false"
              clearable
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="items in item.list"
                :key="items.value"
                :label="items.label || items.name"
                :value="items.label || items.name"
              />
            </el-select>
          </el-form-item>
        </template>
      </template>
    </tabCom>
  </div>
</template>
<script lang="ts" setup>
import tabCom from "@/components/table/indexcopy.vue"
// import { gethomeStatistics } from "@/api/home/index"
import { ref, onMounted } from "vue"
import upfilebox from "@/components/table/upfile.vue"

onMounted(() => {
  init()
})
// 时间选择限定范围
const chooseTimeChange = (time: any) => {
  const starTime = JSON.parse(JSON.stringify(time[0]))
  const endTime = JSON.parse(JSON.stringify(time[1]))
  const minTime = new Date(insertStr(insertStr(starTime, 4, "-"), 7, "-")).getTime()
  const maxTime = new Date(insertStr(insertStr(endTime, 4, "-"), 7, "-")).getTime()
  const allow = 2592000000 //30天
  if (maxTime - minTime > allow) {
    ElMessage.warning("选择范围请在30天以内!")
    chaxunState.value = false
  } else {
    chaxunState.value = true
  }
}
// 接口请求配置
const operationApiA = ref<any>([
  { type: "add", interface: "/bystanderRecord/insertOrUpdate" },
  { type: "update", interface: "/bystanderRecord/insertOrUpdate" },
  { type: "search", interface: "/bystanderRecord/selectAll" },
  { type: "delete", interface: "/bystanderRecord/deleteByIds" },
  { type: "svg", interface: "/bystanderRecord/export" }
])

// 搜索配置
const searchDataListJy = [
  { name: "id", title: "id" },
  {
    name: "bystanderType",
    title: "旁站类型",
    type: "select",
    list: [
      { value: 1, label: "吊装工程", name: "吊装工程", id: 1 },
      { value: 2, label: "防水工程", name: "防水工程", id: 2 },
      { value: 3, label: "混凝土工程", name: "混凝土工程", id: 3 },
      { value: 4, label: "通用", name: "通用", id: 4 }
    ]
  },
  { name: "constructionProgrammeNum", title: "施工方案编号(通用)" },
  { name: "constructionUnit", title: "施工单位" },
  { name: "engineeringName", title: "工程名字" },
  { name: "num", title: "编号" },
  { name: "keepNum", title: "取号存档编号" },
  { name: "sysCode", title: "系统代号" },
  { name: "sonItemCode", title: "子项代号" },
  { name: "staffing", title: "人员配备" },
  { name: "partProcess", title: "部位工序" },
  { name: "constructionUnit", title: "施工单位" },
  {
    name: "isCompliance",
    title: "是否合规",
    type: "select",
    list: [
      { value: 0, label: "待查看", name: "待查看", id: 0 },
      { value: 1, label: "合规", name: "合规", id: 1 },
      { value: 2, label: "不合规", name: "不合规", id: 2 }
    ]
  },
  { name: "startTime", title: "开始时间", type: "datetime" },
  { name: "endTime", title: "结束时间", type: "datetime" }
]
// 添加配置
const searchDataListJyEdit = [
  {
    name: "bystanderType",
    title: "旁站类型",
    type: "select",
    showArr: [1, 2, 3, 4],
    list: [
      { value: 1, label: "吊装工程", name: "吊装工程", id: 1 },
      { value: 2, label: "防水工程", name: "防水工程", id: 2 },
      { value: 3, label: "混凝土工程", name: "混凝土工程", id: 3 },
      { value: 4, label: "通用", name: "通用", id: 4 }
    ]
  },
  { name: "num", title: "编号", showArr: [1, 2, 3, 4] },
  { name: "engineeringName", title: "工程名称	", showArr: [1, 2, 3, 4] },
  { name: "constructionUnit", title: "施工单位", showArr: [1, 2, 3, 4] },
  { name: "sonItemCode", title: "子项代号", showArr: [1, 2, 3, 4] },
  { name: "sysCode", title: "系统代号", showArr: [1, 2, 3, 4] },
  { name: "weather", title: "天气", showArr: [1, 2, 3, 4] },
  { name: "constructionProgramme", title: "施工方案", showArr: [1, 2] },
  { name: "weconstructionProgrammeNumather", title: "施工方案编号", showArr: [4] },
  { name: "constructionProgrammeSign", title: "施工方案签字", showArr: [1] },
  { name: "partProcess", title: "部位工序", showArr: [1, 3, 4] },
  { name: "staffing", title: "人员配备", showArr: [1, 2, 3] },
  { name: "mechanicalCondition", title: "机械配备情况", showArr: [1, 2, 3] },
  { name: "hoistingParam", title: "吊装参数", showArr: [1] },
  { name: "emergencyMeasure", title: "应急措施", showArr: [1] },
  { name: "hoistingStartTime", title: "吊装开始时间", showArr: [1], type: "datetime" },
  { name: "hoistingEndTime", title: "吊装结束时间", showArr: [1], type: "datetime" },
  { name: "discoveringProblemsHandlingMeasures", title: "发现问题及处理措施", showArr: [1, 2, 3, 4] },

  { name: "materialAcceptance", title: "材料验收", showArr: [2] },
  { name: "technicalDisclosure", title: "技术交底", showArr: [2, 3] },
  { name: "standardsImplementation", title: "标准执行情况/施工情况", showArr: [1, 4] },
  { name: "annexFileUrl", title: "附件文件", type: "file", showArr: [1, 2, 3, 4], prop: "annexFileName" },
  { name: "remarks", title: "备注", showArr: [1, 2, 3, 4] }
]
// 表单配置
const tableDataRuleA = ref([
  { prop: "id", label: "id" },
  {
    prop: "bystanderType",
    label: "旁站类型",
    type: "select",
    showArr: [1, 2, 3, 4],
    list: [
      { value: 1, label: "吊装工程", name: "吊装工程", id: 1 },
      { value: 2, label: "防水工程", name: "防水工程", id: 2 },
      { value: 3, label: "混凝土工程", name: "混凝土工程", id: 3 },
      { value: 4, label: "通用", name: "通用", id: 4 }
    ]
  },
  { prop: "num", label: "编号", showArr: [1, 2, 3, 4] },
  { prop: "engineeringName", label: "工程名称	", showArr: [1, 2, 3, 4] },
  { prop: "constructionUnit", label: "施工单位", showArr: [1, 2, 3, 4] },
  { prop: "sonItemCode", label: "子项代号", showArr: [1, 2, 3, 4] },
  { prop: "sysCode", label: "系统代号", showArr: [1, 2, 3, 4] },
  { prop: "weather", label: "天气", showArr: [1, 2, 3, 4] },
  { prop: "constructionProgramme", label: "施工方案(吊装/防水)", showArr: [1, 2] },
  { prop: "weconstructionProgrammeNumather", label: "施工方案编号(通用)", showArr: [4] },
  { prop: "constructionProgrammeSign", label: "施工方案签字(吊装工程)", showArr: [1] },
  { prop: "partProcess", label: "部位工序(吊装，防水，通用)", showArr: [1, 3, 4] },
  { prop: "staffing", label: "人员配备(非通用)", showArr: [1, 2, 3] },
  { prop: "mechanicalCondition", label: "机械配备情况", showArr: [1, 2, 3] },
  { prop: "hoistingParam", label: "吊装参数(吊装)", showArr: [1] },
  { prop: "emergencyMeasure", label: "应急措施(吊装)", showArr: [1] },
  { prop: "hoistingStartTime", label: "吊装开始时间(吊装)", showArr: [1], type: "tiem" },
  { prop: "hoistingEndTime", label: "吊装结束时间(吊装)", showArr: [1], type: "tiem" },
  { prop: "discoveringProblemsHandlingMeasures", label: "发现问题及处理措施", showArr: [1, 2, 3, 4] },

  { prop: "materialAcceptance", label: "材料验收(防水工程)", showArr: [2] },
  { prop: "technicalDisclosure", label: "技术交底(防水/混凝土)工程", showArr: [2, 3] },
  { prop: "standardsImplementation", label: "标准执行情况/施工情况", showArr: [1, 4] },
  { prop: "annexFileName", label: "附件文件", type: "filename", assoc: "annexFileUrl" },
  { prop: "remarks", label: "备注" }
  // {prop: 'operate',label: '操作'},
])
// 初始化
const init = () => {}
// 表单刷新
const Refresh = () => {
  //用户数据概览
}
// 搜索回调
const searchCallback = (search: any) => {}
const loading = ref<boolean>(false)
const gailan = ref<any>({})
const gethomeStatisticsStar = (obj: any = {}) => {
  // loading.value = true
  // gethomeStatistics(obj).then((res: any) => {
  //   gailan.value = res.data
  //   loading.value = false
  // })
}
</script>
<style scoped lang="scss">
.search-wrapper {
  margin: 0 auto;
  width: 98.5%;
  margin-top: 10px;
}
</style>
